<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="../../template/tagedu.xhtml"
                xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:define name="title">
        <title><h:outputText value="TAG - Cadastro Unidade"/></title>
        <f:metadata>
            <f:viewParam name="organization" value="#{unitySearch.organizationID}"/>
            <f:viewParam name="type" value="#{unitySearch.organizationType}"/>
        </f:metadata>
    </ui:define>
    
    <ui:define name="content">
        <f:event type="preRenderComponent" listener="#{unitySearch.init()}"/>
        <h:outputText styleClass="organizationName" value="Consulta de #{unitySearch.getOrganizationName()}"/>
        <h:form id="unitySearchForm" styleClass="searchForm">
            <p:messages id="message"/>
            <h:panelGroup id="unitySearchResultGroup">
                <p:dataTable value="#{unitySearch.unities}" var="unity" paginator="true" rows="10" lazy="true"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="10,25,50">
                    <p:column filterMatchMode="contains" filterStyle="width: 200px"
                              filterBy="#{unity.name}">
                        <f:facet name="header">
                            <h:outputText value="Unidade"/>
                        </f:facet>
                        <h:outputLink value="../edit/unityEdit.xhtml">
                            <f:param name="unity" value="#{unity.id}"/>
                            <f:param name="type" value="#{unitySearch.organizationType}"/>
                            <h:outputText value="#{unity.name}"/>
                        </h:outputLink>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Capacidade"/>
                        </f:facet>
                        <h:outputText value="#{unity.capacity}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Total de Alunos"/>
                        </f:facet>
                        <h:outputText value="#{unitySearch.loadTotalMatriculatedChildren(unity)}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Opções"/>
                        </f:facet>
                        <p:commandButton icon="ui-icon-search" ajax="true"
                                         oncomplete="editActor.show();"
                                         action="#{unitySearch.edit()}">
                            <f:setPropertyActionListener value="#{unity}" target="#{unitySearch.unity}"/>
                        </p:commandButton>
                        <p:commandButton icon="ui-icon-close" ajax="true" update=":removeUnityForm"
                                         oncomplete="confirmExclusion.show();" disabled="#{not unitySearch.dependecyCheck(unity)}">
                            <f:setPropertyActionListener value="#{unity}" target="#{unitySearch.unity}"/>
                        </p:commandButton>
                    </p:column>
                </p:dataTable>
            </h:panelGroup>
        </h:form>
    </ui:define>
    
    <ui:define name="modals">
        <p:dialog modal="true" header="Excluir Unidade" widgetVar="confirmExclusion" resizable="false">
            <h:form id="removeUnityForm">
                <table width="100%">
                    <tbody>
                        <tr>
                            <td align="center" width="50%">
                                <p:commandButton value="Confirmar" action="#{unitySearch.delete()}" update=":unitySearchForm" onclick="confirmExclusion.hide();"/>
                            </td>
                            <td align="center" width="50%">
                                <p:commandButton value="Cancelar" onclick="confirmExclusion.hide();"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </h:form>
        </p:dialog>
    </ui:define>
</ui:composition>